/*
@Copyright:LintCode
@Author:   tjyemail
@Problem:  http://www.lintcode.com/problem/length-of-last-word
@Language: C++
@Datetime: 16-02-09 04:50
*/

class Solution {
public:
    /**
     * @param s A string
     * @return the length of last word
     */
    int lengthOfLastWord(string& s) {
        // Write your code here
        int len = s.length(),pos;
        if (len<1)
            return 0;
        for(pos=len-1;pos;--pos)
            if (s[pos]==' ')
                return len-pos-1;
        return len-pos;
    }
};